package com.deng.mapper;

import com.deng.model.Faves;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Author 邓小熙
 * @Date 2022/5/20 9:59
 * @Version 1.0
 */
@Mapper
@Component
public interface FavesMapper {
    /**
     * 检查是否已经收藏
     * @param paperId
     * @param userId
     * @return
     */
    @Select("SELECT * FROM social_blog.faves WHERE user_id=#{userId} AND paper_id=#{paperId}")
    Faves findFavesItem(@Param("userId") int userId, @Param("paperId")int paperId);
    /**
     * 添加收藏
     * @param userId
     * @param paperId
     * @return
     */
    @Insert("INSERT INTO social_blog.faves(user_id,paper_id) VALUES(#{userId},#{paperId})")
    int insertFavesItem(@Param("userId") int userId, @Param("paperId")int paperId);

    /**
     * 通过某用户，当前的页数来查找收藏（有限制）
     * @param userId
     * @param page
     * @param limit
     * @return
     */
    @Select("SELECT * FROM social_blog.faves WHERE user_id=#{userId} LIMIT #{page},#{limit}")
    List<Faves> findAllFavesItem(@Param("userId") int userId,@Param("page") int page,@Param("limit") int limit);
    /**
     * 通过某用户，查找全部收藏（无限制）
     * @param userId
     * @return
     */
    @Select("SELECT * FROM social_blog.faves WHERE user_id=#{userId}")
    List<Faves> findAllFavesItemNoLimit(@Param("userId") int userId);

    /**
     * 删除收藏文章
     * @param userId
     * @param paperId
     * @return
     */
    @Delete("DELETE FROM social_blog.faves WHERE user_id=#{userId} AND paper_id=#{paperId}")
    int deleteFaverItem(@Param("userId") int userId, @Param("paperId")int paperId);
}
